package com.stefan.service.impl;


import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@SpringBootTest
@ExtendWith(SpringExtension.class)
public class CartServiceImplTester {
    @Autowired
    private  CartServiceImpl cartService;
    @Test
    public void testAddItemToCart() {
        // 测试添加商品到购物车
        cartService.addItemToCart("user1", "product1", 1);
        cartService.addItemToCart("user1", "product2", 2);
        cartService.addItemToCart("user1", "product3", 1);
    }
    @Test
    public void testUpdateItemToCart() {
        // 测试添加商品到购物车
        cartService.addItemToCart("user1", "product3", 3);
    }
    @Test
    public void testGetItemFromCart() {
        // 测试获取用户购物车中的特定商品
        System.out.println(cartService.getItmeFromCart("user1", "product3"));
    }
    @Test
    public void testGetAllItemsFromCart() {
        // 测试获取用户购物车中的所有商品
        cartService.getAllItmeFromCart("user1").forEach((key, value) -> {;
            System.out.println("Product ID: " + key + ", Quantity: " + value);
        });
        System.out.println();
    }
    @Test
    public void testRemoveItemFromCart() {
        // 测试从购物车中移除商品
        cartService.removeItemFromCart("user1", "product1");
        System.out.println(cartService.getAllItmeFromCart("user1"));
    }
    @Test
    public void testClearCart() {
        // 测试清空购物车
        cartService.clearCart("user1");
        System.out.println(cartService.getAllItmeFromCart("user1"));
    }

}


